package com.sdkj.recruit.service.impl;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sdkj.recruit.dao.IUserDao;
import com.sdkj.recruit.model.User;
import com.sdkj.recruit.service.ITokenService;
@Service("tokenService")
public class TokenService implements ITokenService {
	
	@Autowired
	private IUserDao userDao;

	@Override
	public boolean isTokenValid(String token) {
		
		// 根据token 获取用户
		User user =userDao.queryUserByToken(token);
		if(user==null){
			return false;
		}
		
		// 用户停用
		if(user.getAccountStatus()==1){
			return false;
		}
		
		Date d = user.getTokenTime();
		long expire =user.getExpireTime();
		Date current=new Date();
        if(current.getTime()>d.getTime()+expire*1000){
            return false;
        }
		return true;
	}

}
